<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="js/js.cookie.js"></script>
    <style>
        *{margin: 0;padding: 0;}
        ul li{
            list-style: none;
            margin-left: 10px;
            margin-bottom: 5px;
        }
        .box{
            width: 300px;
            height: 300px;
            background-color: skyblue;
            margin-top: 100px;
            margin-left: 50px;
            box-sizing: border-box;
        }
        p{
            font-size: 20px;
            font-weight: bold;
            padding-top: 20px;
            margin-bottom: 5px;
            margin-left: 10px;
        }
        /* .text{
            width: 250px;
            height: 30px;
            background-color: antiquewhite;
            border-radius: 5px;
            margin-left: 10px;
            margin-top: 20px;
            display: none;
            line-height: 30px;
        } */
    </style>
</head>
<body>
    <ul class="box">
        <p>注册</p>
        <li>用户名:<input type="text" id="uname" placeholder="请输入用户名"></input></li>
        <li>密&nbsp &nbsp码:<input type="password" id="pwd" placeholder="请输入密码"></input></li>
        <li>手机号:<input type="text" id="tel" placeholder="请输入手机号"></input></li>
        <li>
            <button type="submit">提交</button>
            <button type="reset">重置</button>
        </li>
        <div class="text"></div>
    </ul>
    <script>
        var oUname=document.querySelector("#uname");
        var oPwd=document.querySelector("#pwd");
        var oTel=document.querySelector("#tel");
        var oBtns=document.querySelectorAll("button");
        var oText=document.querySelector(".text");

        oBtns[0].onclick=function(){
            var oUser=JSON.parse(Cookies.get("logins")||'[]');
            // 正则表达式
            var reg1=/\w{6,}/;
            var str1=oUname.value;
            var reg2=/\w{8,16}/;
            var str2=oPwd.value;
            var reg3=/^1[3|4|5|8][0-9]\d{4,8}$/;
            var str3=oTel.value;
            // 判断用户名,密码,手机号是否符合标准
            if(!(reg1.test(str1))){
                alert("用户名只能为字母,数字,下划线,且长度大于6位");
                return;
            }else if(!(reg2.test(str2))){
                alert("密码长度为8至16位");
                return;
            }else if(!(reg3.test(str3))){
                alert("手机号码不合法!");
                return;
            }else{
                var oUser={ name:oUname.value , pwd:oPwd.value, tel:oTel.value}
                Cookies.set("logins",oUser,{expires:10});
                alert("登录成功!");
            }
        }
        oBtns[1].onclick=function(){
            oUname.value="";
            oPwd.value="";
            oTel.value="";
        }
    </script>
</body>
</html>